package filter

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

func init() {
	beego.InsertFilter("/new", beego.BeforeRouter, FilterUser)
	beego.InsertFilter("/del/:tid", beego.BeforeRouter, FilterUser)
	beego.InsertFilter("/moddfy/:tid", beego.BeforeRouter, FilterUser)
}

func FilterUser(ctx *context.Context) {
	ok := ctx.Input.Session("user")
	if ok == nil && ctx.Request.RequestURI != "/login" {
		ctx.Redirect(302, "/login")
	}
}

func IsLogin(ctx *context.Context) (b bool) {
	ok := ctx.Input.Session("user")
	if ok == nil {
		return false
	}
	return true
}
